package com.smartboot.plus.ignite.listener;

import com.smartboot.plus.holder.BrokerContextHolder;
import org.apache.ignite.internal.processors.security.PublicAccessJob;
import org.apache.ignite.lang.IgniteRunnable;
import org.apache.ignite.plugin.security.SecurityPermission;
import org.apache.ignite.plugin.security.SecurityPermissionSet;
import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
import tech.smartboot.feat.core.common.logging.Logger;
import tech.smartboot.feat.core.common.logging.LoggerFactory;

public class RefreshTopicBroadcast implements IgniteRunnable, PublicAccessJob {
    private static final Logger LOGGER = LoggerFactory.getLogger(RefreshTopicBroadcast.class);

    private String username;

    public RefreshTopicBroadcast(String username) {
        this.username = username;
    }


    @Override
    public void run() {
        BrokerContextHolder.getMqttAclCacheMap().remove(username);
        LOGGER.info("刷新{}的权限缓存", username);
    }

    @Override
    public SecurityPermissionSet requiredPermissions() {
        // 创建一个权限构建器
        SecurityPermissionSetBuilder builder = new SecurityPermissionSetBuilder();

        // 添加任务执行权限
        builder.appendTaskPermissions(this.getClass().toString(),
                SecurityPermission.TASK_EXECUTE,
                SecurityPermission.TASK_CANCEL);

        // 构建并返回权限集
        return builder.build();
    }
}
